package com.shg.web.ztest;



import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.shg.bean.Book;
import com.shg.bean.OrderItem;
import com.shg.bean.PageView;
import com.shg.bean.QueryResult;
import com.shg.bean.SoldBook;
import com.shg.service.SoldBookService;

public class SoldBookServiceTest {

	private static SoldBookService soldBookService;
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		ApplicationContext context=new ClassPathXmlApplicationContext("application-web-context.xml");
		soldBookService=(SoldBookService)context.getBean("soldBookServiceBean");
	}

	@Test
	public void testInsert() {
		SoldBook entity=new SoldBook();
		Book book=new Book();
		book.setId("297ec07636e242200136e24a62d60003");
		entity.setPrice(33.2);
		OrderItem item=new OrderItem();
		item.setId("201203211056341111");
		entity.setOrderItem(item);
		entity.setBook(book);
		soldBookService.insert(entity);
	}
	@Test
	public void getBooK(){
		PageView<SoldBook> pageView=new PageView<SoldBook>(3, 1);
		String bookid="402889673629f13401362a0371710000";
		QueryResult<SoldBook> books=null;
		try {
			books = (QueryResult<SoldBook>) soldBookService.getSoldRecord(pageView, bookid);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		for(SoldBook soldBook:books.getResultList()){
			System.out.println(soldBook.getBook().getBookName());
		}
	}
	@Test
	public void testSoldBook(){
		QueryResult<SoldBook> result=null;
		try {
			result = soldBookService.getSoldBook("ff80808135a033220135a033246c0000",0,3);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		for(SoldBook book:result.getResultList()){
			System.out.println(book.getBook().getBookName()+"\t"+book.getPrice()+"\t"+book.getOrderItem().getId());
		}
	}
}
